import Mock from 'mockjs'
import screen from './screen'
import miniapp from './miniapp'

// 设置请求延时和配置
Mock.setup({
  timeout: '100-600',
  responseType: 'json'
})

// 注册所有 mock 接口
const mocks = [
  ...screen,
  ...miniapp
]

// 注册 mock 接口
mocks.forEach(item => {
  Mock.mock(new RegExp(item.url), item.method || 'get', (options) => {
    console.log('Mock request:', options)
    try {
      const result = typeof item.response === 'function' 
        ? item.response(options)
        : item.response
      console.log('Mock response:', result)
      return {
        code: 200,
        data: result,
        message: 'success'
      }
    } catch (error) {
      console.error('Mock error:', error)
      return {
        code: 500,
        data: null,
        message: error.message
      }
    }
  })
})

// 添加全局响应拦截器
Mock.setup({
  timeout: '100-600'
})

export default Mock 